package day0107;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {
	
//	1、int[] array={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//	求出上面数组中0-9分别出现的次数    
	@Test
	public void test1() {
		int[] scoress = new int[] {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		// int count = 0;   如果定义在这  需要在后面加一个count= 0；
		for (int i = 0; i <= 9; i++) { //此处的i不是数组下标
			int count = 0;         //定义在for循环里面，每次遍历完count回到0，不会强制加count = 0;
			for (int j = 0; j < scoress.length; j++) { // j为数组下标
				if (scoress[j] == i) {
					count++;
				}
			}
			System.out.println(i + "的次数是" + count);
			// count = 0;
		}
	}
	
	//找0-9出现次数改进做法
	@Test 
	public void test2() {
		int[] array = new int[] {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int[] num = new int[10];  // 定义一个空的num数组 ，将数到的0-9的次数往里填；count[0]放0的次数……
		for (int i = 0; i < array.length; i++) {   //遍历array数组，当遇到switch，填入对应的case
			switch (array[i]) {
			case 0:  
				num[0]++;
				break;
			case 1:
				num[1]++;
				break;
			case 2:
				num[2]++;
				break;
			case 3:
				num[3]++;
				break;
			case 4:
				num[4]++;
				break;
			case 5:
				num[5]++;
				break;
			case 6:
				num[6]++;
				break;
			case 7:
				num[7]++;
				break;
			case 8:
				num[8]++;
				break;
			case 9:
				num[9]++;
				break;
			default:
				break;
			}
		}
		 //遍历num数组 ，拿到num数组里面已经累加到的值
		for (int i = 0; i < num.length; i++) {
			System.out.println(i + "出现的次数是" + num[i]);
		}
	}
	// 0-9次数
	@Test
	public void test11() {
		int[] array = new int[] {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int count = 0;   //定义在for循环外面  ，每遍历完一次需要令count = 0;
		for (int i = 0; i <= 9; i++) {
			for (int j = 0; j < array.length; j++) {
				if (i == array[j]) {
					count++;
				}
			}
			System.out.println(count);
			count = 0;
		}
	}
	
//	2、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//	要求求出其中的奇数个数和偶数个数。
	@Test
	public void test3() {
		int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int oddNum = 0;
		int evenNum = 0;
		for (int i = 0; i < scores.length; i++) {
			if (scores[i] % 2 == 0) {
				evenNum++;
			}else {
				oddNum++;
			}
		}
		System.out.println("偶数的个数是" + evenNum);
		System.out.println("奇数的个数是" + oddNum);
	}
	
	//3、输入一组学生的成绩，使用数组，然后计算他们的平均值.
	@Test
	public void test4() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("学生数量为");
		int count = scanner.nextInt();
		int[] array = new int[count];  //将学生的数量作为新数组的长度，几个学生就有几个成绩
		double sum = 0;
		for (int i = 0; i < array.length; i++) {
			System.out.println("请输入学生成绩");   //有几个学生重复几次，每次输入新的学生的成绩，并进行相加
			int score = scanner.nextInt();
			sum = sum + score;
		}
		System.out.println("学生的平均成绩为" + (sum / count));
	}
	
	//16、题目：一个5位数，判断它是不是回文数。即12321是回文数，个位与万位相同，十位与千位相同。
	
	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入字符串");
		String str = scanner.next();
		char[] array = str.toCharArray();  // 将String转换成char
		boolean isHuiWen = true;     //假设是回文数
		for (int i = 0; i < array.length / 2; i++) {   //如果是回文数，首尾相同，只需要遍历前一半的，然后跟尾部比较
			if (array[i] != array[array.length - 1 - i]) {
				isHuiWen = false;
				break;
			}
			} if ( isHuiWen == true) {
				System.out.println( "是回文数");
			} else {
				System.out.println("不是回文数");
		}
	}
	
	
//	17、输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。
	@Test
	public void test6() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入字符串");
		String str = scanner.nextLine();
		char[] array = str.toCharArray();
		int letterCount = 0;
		int blankCount = 0;
		int numCount = 0;
		int otherCount = 0;
		for (int i = 0; i < array.length; i++) {
			if ((array[i] >= 'a' && array[i] <= 'z') || (array[i] >= 'A' && array[i] <= 'Z')) {
				letterCount++;
			} else if (array[i] == ' ') {
				blankCount++;
			} else if (array[i] >= '0' && array[i] <= '9') {
				numCount++;
			} else {
				otherCount++;
			}
		}
		System.out.println("英文字母个数为" + letterCount);
		System.out.println("空格个数为" + blankCount);
		System.out.println("数字个数为" + numCount);
		System.out.println("其他字符个数为" + otherCount);
	}
	
//	18、题目：企业发放的奖金根据利润提成。利润(I)低于或等于10万元时，奖金可提10%；
//	利润高于10万元，低于20万元时，低于10万元的部分按10%提成，高于10万元的部分，可可提成7.5%；
//	20万到40万之间时，高于20万元的部分，可提成5%；
//	40万到60万之间时高于40万元的部分，可提成3%；
//	60万到100万之间时，高于60万元的部分，可提成1.5%，高于100万元时，超过100万元的部分按1%提成，
//	从键盘输入当月利润，求应发放奖金总数？
	
	@Test
	public void test7() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入利润（万元）");
		double profit = scanner.nextDouble();
		double price = 0;
		if (profit < 0) {
			System.out.println("没有money");
			return;
		}  if (0 <= profit && profit <= 10) {
			price = profit * 0.1;
		} else if (10 < profit && profit <= 20) {
			price = ( profit - 10) * 0.075 + 1;
		} else if (profit > 20 && profit <= 40) {
			price = ( profit - 20) * 0.05 + 1.75;
		} else if (profit > 40 && profit <= 60) {
			price = (profit - 40) * 0.03 + 2.75;
		} else if (profit > 60 && profit <= 100){
			price = (profit - 60) * 0.015 + 3.35;
		} else {
			price = (profit - 100) * 0.01 + 3.95;
		}
		System.out.println("你所得奖金为" + price + "万元");
	}
	
	@Test
	public void test8() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入利润（万元）");
		int profit = scanner.nextInt(); 
		double price = 0;
		if (profit < 0) {
			System.out.println("没有money");
			return;
		}
		switch (profit / 10) {
		case 0:
			price = profit * 0.1;
			break;
		case 1:
			price = ( profit - 10) * 0.075 + 1;
			break;
		case 2:
		case 3:
			price = ( profit - 20) * 0.05 + 1.75;
			break;
		case 4:
		case 5:
			price = (profit - 40) * 0.03 + 2.75;
			break;
		case 6:
		case 7:
		case 8:
		case 9:
			price = (profit - 60) * 0.015 + 3.35;
			break;
		default:
			price = (profit - 100) * 0.01 + 3.95;
			break;
		}
		System.out.println("你所得奖金为" + price + "万元");
}
}
